﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace BookOnline.Data
{
    public class NewsController:SqlDataProvider
    {
        public List<Data.News> GetAllData()
        {
            List<Data.News> list = new List<Data.News>();
            using (SqlCommand command = new SqlCommand("NewsSelectAll", getConnect()))
            {
                News news = new News();
                command.CommandType = CommandType.StoredProcedure;
                SqlDataReader dr = command.ExecuteReader();
                if (dr.HasRows)
                {
                    while (dr.Read())
                    {
                        list.Add(news.NewsIDataReader(dr));
                    }
                }
                dr.Close();
                news = null;
            }
            return list;
        }

        public List<Data.News> GetDataByID(string id)
        {
            List<Data.News> list = new List<News>();
            using (SqlCommand command = new SqlCommand("NewsSelect", getConnect()))
            {
                News obj = new News();
                command.CommandType = CommandType.StoredProcedure;
                command.Parameters.Add(new SqlParameter("@NewsID",id));
                SqlDataReader dr = command.ExecuteReader();
                if (dr.HasRows)
                {
                    while (dr.Read())
                    {
                        list.Add(obj.NewsIDataReader(dr));
                    }
                }
                dr.Close();
                obj = null;
            }
            return list;
        }
    }
}
